/**
 * @(#) CommonProxy.as
 *
 * @date		2009. 04. 6.
 * @version		1.0
 * @author		Shin, Yunwoo
 * @description	 국경일 및 휴일정보 Proxy - Proxy
 * 				모든 proxy는 여기에서 상속 받는다.
 */
package com.skt.common_hr.common
{
	import com.skt.common_hr.common.Variables;
	import com.wcl.dataloader.*;
	
	import flash.net.URLLoader;
	
	import mx.managers.CursorManager;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	
	public class LoaderUtil
	{
		protected var loader:URLLoader = new URLLoader();
		
		public var retCode:int;
		public var retText:String;
		public var faultDetail:String;
		
		
		private var fResult:Function = null;
		private var fFault:Function = null;
		
		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function LoaderUtil(result:Function=null, fault:Function=null)
		{
			fResult = result;
			fFault = fault;
		}
		
		public function load(rfcName:String, param:Object, result:Function=null, fault:Function=null):void
		{
			CursorManager.setBusyCursor();
			var loader:IDataLoader = DataLoaderFactory.getDataLoader(rfcName, Variables.serverName); 
			if(result!=null)
				fResult = result;
			if(fault!=null)
				fFault = fault;
			loader.load(param, parseResult, parseFault); 
		}
		
		private function parseResult(event:ResultEvent):void
		{
			retCode = event.result["RETCODE"];
			retText = event.result["RETTEXT"];
			fResult(event);
			CursorManager.removeBusyCursor();
		}
		
		private function parseFault(event:FaultEvent):void
		{
			retCode = -1;
			retText = "["+event.fault.faultCode+"]"+event.fault.faultString;
			faultDetail = event.fault.faultDetail;
			fFault(event);	
			CursorManager.removeBusyCursor();
		}
	}
}